package com.example.cartmanage.chewei.adapter

import android.graphics.Color
import android.view.LayoutInflater
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.example.cartmanage.R
import com.example.cartmanage.chewei.entity.CheweiEntityItem
import com.example.cartmanage.chewei.entity.SearchCheweiEntityItem
import com.example.cartmanage.databinding.ItemCheweiBinding

class CheweiAdapter2(private val dataList: List<CheweiEntityItem>) :
    RecyclerView.Adapter<CheweiAdapter2.CheweiViewHolder>() {

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): CheweiViewHolder {
        val binding = ItemCheweiBinding.inflate(LayoutInflater.from(parent.context), parent, false)
        return CheweiViewHolder(binding)
    }

    override fun getItemCount(): Int = dataList.size

    override fun onBindViewHolder(holder: CheweiViewHolder, position: Int) {
        val item = dataList[position]
        holder.bind(item)
    }

    inner class CheweiViewHolder(private val binding: ItemCheweiBinding) :
        RecyclerView.ViewHolder(binding.root) {

        fun bind(item: CheweiEntityItem) {
            binding.apply {
                tvCheweiNum.text = item.spaceNumber
                tvArea.text = "所属区域：${item.areaName}"
                tvType.text = "车位类型：${item.spaceType}"
                tvStatus.text = item.spaceStatus
                tvLicensePlate.text = "车牌号：${item.licensePlate}"
                tvRemarks.text = "备注：${item.remarks}"
                tvUserName.text = "用户：${item.userName}"

                // 设置状态颜色
                tvStatus.setTextColor(
                    when (item.spaceStatus) {
                        "空闲" -> Color.GREEN
                        "已占用" -> Color.BLUE
                        "维护中" -> Color.YELLOW
                        else -> tvStatus.currentTextColor
                    }
                )
            }
        }
    }
}
class CheweiAdapter : BaseQuickAdapter<CheweiEntityItem, BaseViewHolder>(R.layout.item_chewei) {
    override fun convert(helper: BaseViewHolder, item: CheweiEntityItem) {
        helper.setText(R.id.tvCheweiNum, item.spaceNumber)
        helper.setText(R.id.tvArea, "所属区域：${item.areaName}")
        helper.setText(R.id.tvType, "车位类型：${item.spaceType}")
        helper.setText(R.id.tvStatus, item.spaceStatus)

        // 额外字段展示（可在item_chewei.xml中添加TextView并绑定）
        helper.setText(R.id.tvLicensePlate, "车牌号：${item.licensePlate}")
        helper.setText(R.id.tvRemarks, "备注：${item.remarks}")
        helper.setText(R.id.tvUserName, "用户：${item.userName}")

        // 状态颜色
        if (item.spaceStatus == "空闲"){
            helper.getView<TextView>(R.id.tvStatus).setTextColor(Color.GREEN)
        }else if (item.spaceStatus == "已占用"){
            helper.getView<TextView>(R.id.tvStatus).setTextColor(Color.BLUE)
        }else if (item.spaceStatus == "维护中"){
            helper.getView<TextView>(R.id.tvStatus).setTextColor(Color.YELLOW)
        }

    }
}
class CheweisearchAdapter : BaseQuickAdapter<SearchCheweiEntityItem, BaseViewHolder>(R.layout.item_chewei) {
    override fun convert(helper: BaseViewHolder, item: SearchCheweiEntityItem) {
        helper.setText(R.id.tvCheweiNum, item.spaceNumber)
        helper.setText(R.id.tvArea, "所属区域：${item.areaName}")
        helper.setText(R.id.tvType, "车位类型：${item.spaceType}")
        helper.setText(R.id.tvStatus, item.spaceStatus)

        // 额外字段展示（可在item_chewei.xml中添加TextView并绑定）
        helper.setText(R.id.tvLicensePlate, "车牌号：${item.licensePlate}")
        helper.setText(R.id.tvRemarks, "备注：${item.remarks}")
        helper.setText(R.id.tvUserName, "用户：${item.userName}")

        // 状态颜色
        if (item.spaceStatus == "空闲"){
            helper.getView<TextView>(R.id.tvStatus).setTextColor(Color.GREEN)
        }else if (item.spaceStatus == "已占用"){
            helper.getView<TextView>(R.id.tvStatus).setTextColor(Color.BLUE)
        }else if (item.spaceStatus == "维护中"){
            helper.getView<TextView>(R.id.tvStatus).setTextColor(Color.YELLOW)
        }

    }
}
